package com.htg.util;

import android.view.View;
import android.view.ViewGroup;

public class UtilView {

    public static void deductMarginBottom(View view, int pixel) {
        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        layoutParams.setMargins(layoutParams.leftMargin,
                layoutParams.topMargin,
                layoutParams.rightMargin,
                layoutParams.bottomMargin - pixel);
        view.setLayoutParams(layoutParams);
    }

    public static void addMarginBottom(View view, int pixel) {
        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        layoutParams.setMargins(layoutParams.leftMargin,
                layoutParams.topMargin,
                layoutParams.rightMargin,
                layoutParams.bottomMargin + pixel);
        view.setLayoutParams(layoutParams);
    }

    public static void setMarginBottom(View view, int pixel) {
        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        layoutParams.setMargins(layoutParams.leftMargin,
                layoutParams.topMargin,
                layoutParams.rightMargin,
                pixel);
        view.setLayoutParams(layoutParams);
    }


    public static void addMarginLeft(View view, int pixel) {
        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        layoutParams.setMargins(layoutParams.leftMargin + pixel,
                layoutParams.topMargin,
                layoutParams.rightMargin,
                layoutParams.bottomMargin);
        view.setLayoutParams(layoutParams);
    }

    public static void addMarginRight(View view, int pixel) {
        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        layoutParams.setMargins(layoutParams.leftMargin,
                layoutParams.topMargin,
                layoutParams.rightMargin + pixel,
                layoutParams.bottomMargin);
        view.setLayoutParams(layoutParams);
    }
}
